import base from './base';
import vm from '@/main';

export default class app extends base {
    /**
    * [getAuthList 获取app组列表]
    *
    * @return  {[type]}  [return description]
    */
    static getGroupList (params) {
        let url = 'AppGroup/index';
        return base.get(url, params);
    }

    /**
    * [delUser 删除App组]
    *
    * @return  {[type]}  [return description]
    */
    static getAllGroup (params) {
        let url = 'AppGroup/getAll';
        return base.get(url, params).then(data => {
            // vm.$Message.success(data.msg);
            return data;
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }
    /**
    * [delUser 删除App组]
    *
    * @return  {[type]}  [return description]
    */
    static delAppGroup (params) {
        let url = 'AppGroup/del';
        return base.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
    * [changeStatus 变更app组状态]
    *
    * @return  {[type]}  [return description]
    */
    static changeStatus (params) {
        let url = 'AppGroup/changeStatus';
        return base.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
     * [InterfaceList 获得hash值]
     *
     * @return  {[type]}  [return description]
     */
    static getHash (params) {
        let url = 'InterfaceList/getHash';
        return base.get(url, params).then(data => {
            // vm.$Message.success(data.msg);
            return data;
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
    * [modifyUser 修改应用组 包括 增加/编辑]
    *
    * @return  {[type]}  [return description]
    */
    static modifyAppGroup (url, params) {
        return base.post(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /* ----------  以下为应用页面请求  ---------- */

    /*
    * [getAuthList 获取app组列表]
    *
    * @return  {[type]}  [return description]
    */
    static getAppList (params) {
        let url = 'App/index';
        return base.get(url, params);
    }

    /**
     * [getAppInfo 获取应用信息]
     *
     * @return  {[type]}  [return description]
     */
    static getAppInfo (params) {
        let url = 'App/getAppInfo';
        return base.get(url, params).then(data => {
            // vm.$Message.success(data.msg);
            return data;
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
    * [delUser 删除App]
    *
    * @return  {[type]}  [return description]
    */
    static delApp (params) {
        let url = 'App/del';
        return base.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }

    /**
    * [changeStatus 变更app状态]
    *
    * @return  {[type]}  [return description]
    */
    static changeAppStatus (params) {
        let url = 'App/changeStatus';
        return base.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }
    /**
    * [modifyUser 修改应用 包括 增加/编辑]
    *
    * @return  {[type]}  [return description]
    */
    static modifyApp (url, params) {
        return base.post(url, params, true).then(data => {
            vm.$Message.success(data.msg);
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }
    static refreshAppSecret (params) {
        let url = 'App/refreshAppSecret';
        return base.get(url, params, true).then(data => {
            vm.$Message.success(data.msg);
            return data.data;
        }).catch(error => {
            vm.$Message.error(error.message);
            console.error(error);
            throw error;
        });
    }
}
